/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sunspotworld;

import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ISwitch;

/**
 *
 * @author Ohad
 */
public class ChooseModeOfOperation {
    EDemoBoard eDemoBoard;
    AirText airText;

    public ChooseModeOfOperation(EDemoBoard eDemoBoard, AirText airText) {
        this.eDemoBoard = eDemoBoard;
        this.airText=airText;
    }
    
    

    
    public ModeOfOperation chooseMasterOrSlave() {
        System.out.println("Allow choosing between active and passive");
        boolean needToChoose=true;
        ModeOfOperation result=null;
        
        ISwitch[] swithces=eDemoBoard.getSwitches();
        while (needToChoose) {
            System.out.println("Waiting for user input");
            airText.swingThis("Active or", 3);
            airText.swingThis("Passive ?", 3);
            if (swithces[0].isClosed()) {
                result=ModeOfOperation.ACTIVE;
                System.out.println("Active mode");
                needToChoose=false;
            }
            if (swithces[1].isClosed()) {
                result=ModeOfOperation.PASSIVE;
                System.out.println("Passive mode");
                needToChoose=false;
            }
        }
        System.out.println("Done choosing active or passive");
        return(result);
           
    }

}
